home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / netconnect3 / amirc_33 / rexx / trans.amirx < prev    next >
Text File  |  1999-12-26  |  2KB  |  72 lines

  1. /*
  2.    $VER:English/German-Translator 1.5ß (21.03.99) C.Birchinger (Joker)
  3.    License: GPL (so people stop ask me if they can use this code)
  4. */
  5.  
  6. maxhits=5      /* Default max.hits */
  7. boldtxt=1      /* Use bold */
  8.  
  9. /* --------------------------------------------------------------*/
  10.  
  11. parse arg argument
  12. revarg=reverse(argument)
  13. parse var revarg hits word
  14. hits=reverse(hits);word=reverse(word)
  15. if datatype(hits)~='NUM' then do
  16.     word=word||hits
  17.     hits=maxhits
  18. end    
  19.  
  20. if word='' then do
  21.     "echo P="d2c(27)"b«e/g» Usage: trans <words> [<max.hits>]"
  22.     exit
  23. end 
  24. else hits=strip(hits);word=strip(word)
  25. findword=translate(word,'+',' ')
  26.  
  27. "echo P="d2c(27)"b«e/g» Translating '"||d2c(2)||word||d2c(2)||"' (Max."hits")"
  28. if open(x,'tcp:131.159.72.13/80') then do
  29.     writeln(x,'GET /?search='findword)
  30.     do until index(line,"search result")>0
  31.         line=readln(x)
  32.         if eof(x) then do
  33.             "echo P="d2c(27)"b«e/g» Search for '"||d2c(2)||word||d2c(2)||"' produced no results."
  34.             exit
  35.         end
  36.     end
  37.     parse var line '<STRONG>'foundhits dummy
  38.     if foundhits=1 then "echo P="d2c(27)"b«e/g» "foundhits" search result for '"||d2c(2)||word||d2c(2)||"'"
  39.     else "echo P="d2c(27)"b«e/g» "foundhits" search results for '"||d2c(2)||word||d2c(2)||"'"
  40.   line=readln(x);line=readln(x)
  41.     if foundhits>hits then do
  42.         foundhits=hits
  43.     end
  44.     do i=1 to foundhits
  45.         line=strip(readln(x))
  46.         call htmlout(line)
  47.     end
  48.     call close(x)
  49. end
  50. else
  51.     "echo P="d2c(27)"b«e/g» Error: 'http://www.leo.org/cgi-bin/dict/dict-search.pl' is down or TCP: not mounted."
  52.     exit
  53. end
  54. exit
  55.  
  56. htmlout:
  57. output=arg(1)
  58.  
  59. parse var output dummy 'VALIGN=\"TOP\">' lines '</TD><TD VALIGN=\"TOP\">' linee
  60. output=lines||'-'||linee
  61. do until (index(output,'<B>')=0)
  62.     cut=index(output,'<B>')
  63.     if cut~=0 then output=insert(d2c(2),delstr(output,cut,3),cut-1,1)
  64.     cut=index(output,'</B>')
  65.     if cut~=0 then output=insert(d2c(2),delstr(output,cut,4),cut-1,1)
  66. end
  67.  
  68. if boldtxt=0 then 'echo P='d2c(27)'b«e/g»' compress(output,d2c(2))
  69. else 'echo P='d2c(27)'b«e/g»' output
  70.  
  71. return
  72.